
function CourseDetail() {

}/**
 * Created by lenovo on 2019/2/7.
 */

CourseDetail.prototype.initPlayer = function () {
    var videoInfo = $("#video-info");
    var video_url = videoInfo.attr('data-video-url');
    var cover_url = videoInfo.attr('data-cover-url');
    var player = cyberplayer("playercontainer").setup({
        width:'100%',
        height:'100%',
        file:video_url,
        image:cover_url,
        autostart:false,
        stretching:"uniform",
        repeat:false,
        volume:100,
        controls:true,
        primary:'flash',
        tokenEncrypt:'true',
        ak:'4ffe82368a6241f096c7df505d0eb6d9'
    });
    player.on('beforePlay',function (e) {
        if(!/m3u8/.test(e.file)){
            return;
        }
        xfzajax.get({
            'url':'/course/course_token',
            'data':{
                'video':video_url
            },
            'success':function (result) {
                if(result['code']===200){
                    var token = result['data']['token'];
                    player.setToken(e.file,token);
                }else{
                    alert('token错误！');
                }
            },
            'fail':function (error) {
                console.log(error);
            }
        })
    })
};

CourseDetail.prototype.run = function () {
    this.initPlayer()
};

$(function () {
    var courseDetail = new CourseDetail();
    courseDetail.run()
});